local rule = fk.CreateSkill {
  name = "#hx__1v3_rule&",
  mute = true,
}


rule:addEffect(fk.DrawInitialCards, {
  can_refresh = function (self, event, target, player, data)
    return target == player
  end,
  on_refresh = function (self, event, target, player, data)
    if player.seat == 1 then
      data.num = 8
    end
  end,
})

rule:addEffect(fk.GameStart, {
  can_refresh = function (self, event, target, player, data)
    return true
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    local lord = room:getLord()
    if lord ~= nil and lord:getMark("huixiangmode_sound") == 0 then
      room:broadcastPlaySound("./packages/huixiangkill/audio/skill/kaiju2022")
      room:delay(8000)
      room:addPlayerMark(lord,"huixiangmode_sound", 1)
    end
  end,
})

rule:addEffect(fk.Death, {
  priority = 0.001,
  can_refresh = function (self, event, target, player, data)
    return player.role ~= "lord" and player.dead and player.rest == 0
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    local lord = room:getLord()
    if lord ~= nil then
      room:addPlayerMark(lord, "@huixiangmode_dead", 1)
      player._splayer:setDied(false)
      room:setPlayerRest(player, 1)
      local onlyLvbu = #room:getOtherPlayers(lord) == 0
      if onlyLvbu or lord:getMark("@huixiangmode_dead") >= 5 then
        room:gameOver("lord")
      end
    end
  end,
})

rule:addEffect(fk.TurnEnd, {
  can_refresh = function (self, event, target, player, data)
      return target == player and player.room:getBanner("RoundCount") == 3 and player.role == "lord"
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    room:broadcastPlaySound("./packages/huixiangkill/audio/skill/jianju2022")
    room:gameOver("rebel")
  end,
})


-- -- 盟军死亡进入休整
-- rule:addEffect(fk.BeforeGameOverJudge, {
--   priority = 0.001,
--   can_refresh = function (self, event, target, player, data)
--     return player.role ~= "lord" and player.dead and player.rest == 0
--   end,
--   on_refresh = function (self, event, target, player, data)
--     local room = player.room
--     local lord = room:getLord()
--     if lord ~= nil then
--       room:addPlayerMark(lord, "@huixiangmode_dead", 1)
--       player._splayer:setDied(false)
--       room:setPlayerRest(player, 1)
--       local onlyLvbu = #room:getOtherPlayers(lord) == 0
--       if onlyLvbu or lord:getMark("@huixiangmode_dead") >= 5 then
--         room:gameOver("lord")
--       end
--     end
--   end,
-- })


return rule
